package com.clz.appdesign.appdependence.baseKotlin.mvp


import com.clz.appdesign.appdependence.baseKotlin.BaseActivity

/**
 * @author clz
 * @desc 初始化P，并且连接V，在onDestroy()生命周期中释放P中引用的V。
 */
abstract class MvpActivity<V, P : BasePresenter<V>> : BaseActivity(), BaseView {
    protected var mPresenter: P? = null

    override fun beforeInit() {
        super.beforeInit()
        this.mPresenter = initPresenter()
        mPresenter?.attach(this as V)
    }


    override fun onDestroy() {
        mPresenter?.detach()
        super.onDestroy()
    }

    /**
     * 初始化presenter
     *
     * @return
     */
    abstract fun initPresenter(): P

    override fun showLoading() {
        show2Loading()
    }

    override fun hideLoading() {
        hide2Loading()
    }
}
